﻿using B.S.BaseData.Api.Write.Applicantion.Command.HospitalCommand;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interface;
using B.S.BataBase.Domain.AI;
using MediatR;

namespace B.S.BaseData.Api.Write.Applicantion.CommandHandler.HospitalCommandHandler
{
    public class PatientDeleteCommandHandler : IRequestHandler<PatientDeleteCommand, APIResult<int>>
    {
        private readonly IBaseRepository<PatientModel> _baseRepository;
        public PatientDeleteCommandHandler(IBaseRepository<PatientModel> baseRepository)
        {
            _baseRepository=baseRepository;
        }
        public async Task<APIResult<int>> Handle(PatientDeleteCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            var list = await _baseRepository.GetValues(x => x.Id == request.Id);
            list.IsDel = true;
            var data = await _baseRepository.UpdateAsync(list);
            result.Code = ApiEnum.Fail;
            result.Msg = "患者删除成功";
            result.Data = data;
            return await Task.FromResult(result);
        }
    }
}
